var mslibrary = require('ms-common-library');
module.exports = function (UC, source, config, ArFor, cache) {
    var UserControl = UC;
    var Printer = function (ps, req, Orders_id, keyof) {
        var user_url = config.getdomain(req, '/Products/Order/printer/user/' + Orders_id + '/');
        if (keyof) {
            user_url = config.getdomain(req, '/Products/test/printer/' + Orders_id + '/');
        }
        ps.add(user_url, function (error) {
            console.log(error)
        })
    }
    var router = function (req, res, next) {
        var ps = config.Products_Print_Server;
        if (UserControl.getoff(req.session.key)) {
            var Request = req.body;
            var params = req.params;
            if (params.type == "test") {
                Request.Order_id = Request.id;
            }
            if (Request.Order_id) {
                Printer(ps, req, Request.Order_id, params.type == "test")
                res.Json({
                    "error": 0
                });
            } else {
                res.Json({
                    "error": 1
                });
            }
        } else {

            res.Json({
                "error": 1001
            });

        };

    };

    return router;
};